/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MetricsRetriever.RetrieverComponents;

import java.util.ArrayList;

/**
 *
 * @author Manuel
 */
public class SFMatcher implements Matcher{

    public String matchCommitter(ArrayList<String> collaborators, String committer) {
        if(committer == null || committer.toLowerCase().equals("null") || collaborators.isEmpty())
            return "-1";
        for(int i = 0;i<collaborators.size();i++){
            String currentEntry = collaborators.get(i);
            String[] nicknames = currentEntry.split("-");
            if(nicknames.length == 3){

                //if the collaborator matches 100% return that id
                if(committer.toLowerCase().equals(nicknames[1].toLowerCase())){
                    return(nicknames[0]);
                }
            }
        }
        return "-1";
    }

    public String matchBugOwner(ArrayList<String> collaborators, String owner) {
        if(owner == null || owner.toLowerCase().equals("null") || collaborators.isEmpty())
            return "-1";
        for(int i = 0;i<collaborators.size();i++){
            String currentEntry = collaborators.get(i);
            String[] nicknames = currentEntry.split("-");
            if(nicknames.length == 3){

                //if the collaborator matches 100% return that id
                if(owner.toLowerCase().equals(nicknames[2].toLowerCase())){
                    return(nicknames[0]);
                }
            }
        }
        return "-1";
    }

}
